using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Text;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
using System.Xml;
public class Shop_Member_ShopDeliverType : Member, IRequiresSessionState
{
	protected Literal deliverList;
	protected int UserID = -1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.UserID = base.user.UserID;
		if (base.Request["action"] != null && base.Request["action"] == "delete" && base.Request["deliver_id"] != null && base.Request["deliver_id"] != "")
		{
			int iD = Fetch.GetID("deliver_id");
			try
			{
				Shop_DeliverType shop_DeliverType = new Shop_DeliverType(this.conn);
				if (shop_DeliverType.DeleteDeliver(iD, this.UserID))
				{
					this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script type=\"text/javascript\">alert('删除成功！');location.href='Shop_DeliverType.aspx'</script>");
				}
				else
				{
					this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script type=\"text/javascript\">alert('你无权操作此数据！');</script>");
				}
			}
			catch
			{
				this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script type=\"text/javascript\">alert('输入参数不正确！');</script>");
			}
		}
		this.BindPage();
	}
	protected void BindPage()
	{
		Shop_DeliverType shop_DeliverType = new Shop_DeliverType(this.conn);
		DataTable deliverTypeByUserIDTypeIDStatusDisabled = shop_DeliverType.GetDeliverTypeByUserIDTypeIDStatusDisabled(-1, this.UserID, -1, -1);
		StringBuilder stringBuilder = new StringBuilder();
		if (deliverTypeByUserIDTypeIDStatusDisabled != null && deliverTypeByUserIDTypeIDStatusDisabled.Rows.Count > 0)
		{
			stringBuilder.Append("<ul>");
			foreach (DataRow dataRow in deliverTypeByUserIDTypeIDStatusDisabled.Rows)
			{
				if (dataRow["DeliverAraa"] != null)
				{
					stringBuilder.Append("<li>" + Environment.NewLine);
					stringBuilder.Append(this.GetXMLDeliverToGridView(dataRow["DeliverAraa"].ToString(), dataRow["TypeID"].ToString(), dataRow["Intro"].ToString()));
					stringBuilder.Append("</li>" + Environment.NewLine);
				}
			}
			stringBuilder.Append("</ul>");
		}
		else
		{
			stringBuilder.Append(string.Concat(new string[]
			{
				"&nbsp;&nbsp;&nbsp;&nbsp;",
				Language.GetMemberMsg("Deliver/NotAdd", new string[0]),
				"<a href=\"Shop_AddDeliver.aspx?action=add\">",
				Language.GetMemberMsg("Deliver/Add", new string[0]),
				"</a>"
			}));
		}
		this.deliverList.Text = stringBuilder.ToString();
	}
	protected string GetXMLDeliverToGridView(string DeliverTemplate, string DeliverID, string Intro)
	{
		StringBuilder stringBuilder = new StringBuilder();
		string result;
		if (DeliverTemplate != "")
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.LoadXml(DeliverTemplate);
			XmlNodeList xmlNodeList = xmlDocument.SelectNodes("root/project");
			if (xmlNodeList == null)
			{
				result = "";
				return result;
			}
			foreach (XmlNode xmlNode in xmlNodeList)
			{
				string value = xmlNode.Attributes["name"].Value;
				string value2 = xmlNode.Attributes["lastupdate"].Value;
				XmlNodeList xmlNodeList2 = xmlNode.SelectNodes("deliver");
				stringBuilder.Append("<table class='tableHead' cellspacing=\"0\" cellpadding=\"0\">");
				stringBuilder.AppendFormat("<caption><span>{0}</span><em>最后编辑时间：{2} <a href='Shop_AddDeliver.aspx?action=save&DeliverID=" + DeliverID + "'>编辑</a> - <a href='javascript:deleteProject({1})'>删除</a></em></caption>", value, DeliverID, value2);
				stringBuilder.Append("<tr><th>运送方式</th><th>运送到</th><th>运费</th><th>每增加一件商品</th></tr>");
				foreach (XmlNode xmlNode2 in xmlNodeList2)
				{
					string value3 = xmlNode2.Attributes["name"].Value;
					string value4 = xmlNode2.Attributes["default"].Value;
					string value5 = xmlNode2.Attributes["defIncrement"].Value;
					XmlNodeList xmlNodeList3 = xmlNode2.SelectNodes("item");
					if (xmlNodeList3 != null)
					{
						foreach (XmlNode xmlNode3 in xmlNodeList3)
						{
							stringBuilder.AppendFormat("<tr><td>{0}</td><td class='left'>{1}</td><td>{2}元</td><td>+{3}元</td></tr>", new object[]
							{
								value3,
								xmlNode3.SelectSingleNode("area").InnerXml,
								xmlNode3.SelectSingleNode("price").InnerXml,
								xmlNode3.SelectSingleNode("increment").InnerXml
							});
						}
					}
					stringBuilder.AppendFormat("<tr><td>{0}</td><td class='left'>{1}</td><td>{2}元</td><td>+{3}元</td></tr>", new object[]
					{
						value3,
						"其它",
						value4,
						value5
					});
				}
				stringBuilder.AppendFormat("<tr><td colspan=\"4\" class='left'><span>运费说明：</span>{0}</td></tr>", Intro);
				stringBuilder.Append("</table>");
			}
		}
		result = stringBuilder.ToString();
		return result;
	}
}
